package com.bjsxt.mapper;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AdminMapper {
    //用户登录查询
    @Select("select * from t_admin where aname=#{param1} and apwd=#{param2}")
    Admin selectOne (String aname,String apwd);

    //查询用户全部信息
    @Select("select * from t_admin ")
    List<Admin> select();

     //添加用户的信息
    Integer insert(Admin admin);

    //添加用户对应的角色
    @Insert("insert into t_admin_role values(#{param1},#{param2},default)")
    Integer insertRole(Integer aid,Integer rid);

    //删除用户
    @Delete("delete from t_admin where aid=#{param1}")
    Integer delete(Integer aid);
    //删除用户对应的角色
    @Delete("delete from t_admin_role where aid=#{param1}" )
    Integer deleteRole(Integer aid);

    //查询指定用户对用的角色
    @Select("SELECT r.rid FROM t_admin_role ar JOIN t_role r on ar.rid=r.rid where aid =#{param1}")
    Integer findOne(Integer aid);
    //修改指定用户的信息
    @Update("update t_admin set aname=#{aname},apwd=#{apwd},aphone=#{aphone},starttime=#{starttime} where aid=#{aid}")
    Integer update(Admin admin);

    //修改用户对应的角色
    @Update("update t_admin_role set rid=#{param2} where aid=#{param1}")
    Integer updateRole(Integer aid,Integer rid);
}
